﻿using System.Text.Json;

namespace RuoVea.Iot.MqttClient.Server;

/// <summary>
/// 订阅 获取时候的模型
/// </summary>
public class MqttPayloadDto
{
    /// <summary>
    /// Id
    /// </summary>
    public string Id { get; set; }
    /// <summary>
    /// 调用方法
    /// </summary>
    public string Func { get; set; }
    /// <summary>
    /// 返回调用方法
    /// </summary>
    public string RespFunc { get; set; }
    /// <summary>
    /// 发布者的Id
    /// </summary>
    public string ClientId { get; set; }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public string Serialize()
    {
        var options = new JsonSerializerOptions
        {
            // 设置属性命名策略为 camelCase
            PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
        };

        return JsonSerializer.Serialize(this, options);
    }
}
/// <summary>
/// 
/// </summary>
public class ReqMqttPayloadDto : MqttPayloadDto
{
    /// <summary>
    /// 数据
    /// </summary>
    public MqttData Data { get; set; }
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public string Serialize()
    {
        var options = new JsonSerializerOptions
        {
            // 设置属性命名策略为 camelCase
            PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
        };

        return JsonSerializer.Serialize(this, options);
    }
}

/// <summary>
/// 返回/发布时候的模型
/// </summary>
public class RespMqttPayloadDto : MqttPayloadDto
{
    /// <summary>
    /// 数据
    /// </summary>
    public object Data { get; set; }
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public string Serialize()
    {
        var options = new JsonSerializerOptions
        {
            // 设置属性命名策略为 camelCase
            PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
        };

        return JsonSerializer.Serialize(this, options);
    }
}
/// <summary>
/// 
/// </summary>
public class MqttData
{
    /// <summary>
    /// 
    /// </summary>
    public string Method { get; set; }
    /// <summary>
    /// 
    /// </summary>
    public string Url { get; set; }
    /// <summary>
    /// 
    /// </summary>
    public object Data { get; set; }
    /// <summary>
    /// 
    /// </summary>
    public Dictionary<string, string> Headers { get; set; }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public string Serialize()
    {
        var options = new JsonSerializerOptions
        {
            // 设置属性命名策略为 camelCase
            PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
        };

        return JsonSerializer.Serialize(this, options);
    }
}